define([
  // app.
  "app",

  // modules
  "modules/music"
],

function(app, Music) {
  // Defining the application router, you can attach sub routers here.
  var Router = Backbone.Router.extend({
    initialize: function () {
        var collections = {
        // musics
        musics: new Music.Collection()
      };

      _.extend(this, collections);

      app.useLayout("main-layout").setViews({
        ".musics": new Music.Views.List(collections)
      }).render();
    },

    routes: {
      "": "index",
      "tag/:name": "tag"
      // "tag/:name/music/:id": "detail"
    },

    index: function() {
      // reset state and render
      this.reset();
    },

    tag: function (name) {
      // reset state and render
      this.reset();

      // set the music tag
      this.musics.tag = name;

      // fetch data
      this.musics.fetch();
    },

    go: function () {
      return this.navigate( _.toArray(arguments).join("/"), true);
    },

    reset: function () {
      if (this.musics.length) {
        this.musics.reset();
      }
    }
  });
  return Router;

});
